﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Golem.Indexer.Data;
using System.Net;
using System.Net.Sockets;

using data = Golem.Indexer.Data;

namespace Golem.SearchDatabase
{
    public abstract class Database : IDatabase
    {
        public bool AutoCreate
        {
            get;
            set;
        }

        public int Port
        {
            get;
            set;
        }

        public String Address
        {
            get;
            set;
        }

        public String Username
        {
            get;
            set;
        }

        public String Password
        {
            get;
            set;
        }

        public String DatabaseName
        {
            get;
            set;
        }

        public abstract String ConnectionString
        {
            get;
        }

        public Database(String address, int port, String databaseName, String login, String password, bool autoCreate = false)
        {
            this.Port = port;
            this.DatabaseName = databaseName;
            this.AutoCreate = autoCreate;
            this.Address = address;
            this.Username = login;
            this.Password = password;

            ServicePointManager.DefaultConnectionLimit = 100;

            if (autoCreate)
                InitDatabase();
        }

        public abstract bool IsDatabaseReady();
        public abstract void InitDatabase();

        public abstract void Close();
        public abstract void UpdateMachineState(MachineDescriptor machine);

        public abstract void WriteFiles(MachineDescriptor machine, Protocol protocol, List<FileDescriptor> files);
        public abstract void CreateProtocol(MachineDescriptor machine, Protocol protocol);
        public abstract void DoPermanentProtocolData(MachineDescriptor machine, Protocol protocol);
        public abstract data.SearchResult DoFulltextSearch(string query, IEnumerable<string> types = null);

    }
}
